package com.idc.excel;
import org.apache.poi.ss.usermodel.Cell;

import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.handler.context.CellWriteHandlerContext;

public class FormulaCellWriteHandler implements CellWriteHandler {

    @Override
    public void afterCellDispose(CellWriteHandlerContext context) {
        Cell cell = context.getCell();
        // 判断是否为总价列（第三列，索引2）
        if (cell.getColumnIndex() == 2) {
			int rowNum = cell.getRow().getRowNum() + 1; // 转换为Excel行号
			if (rowNum >= 2) {
				String formula = String.format("A%d*B%d", rowNum, rowNum);
				cell.setCellFormula(formula);
			}
        }
    }
}
